<?php
/*
+--------------------------------------------------------------------------
|   AffiliStore 2
|   ========================================
|   Web: http://www.affilistore.com
|   Email: admin (at) affilistore (dot) com
|	License Type: AffiliStore 2 is NOT open source software and limitations apply 
|   Licence Info: Visit AffiliStore website and click on 'Licence'
+--------------------------------------------------------------------------
*/
if (eregi(".inc.php",$HTTP_SERVER_VARS['PHP_SELF']) || eregi(".inc.php",$_SERVER['PHP_SELF'])) {
	echo "<html>\r\n<head>\r\n<title>Forbidden 403</title>\r\n</head>\r\n<body><h3>Forbidden 403</h3>\r\nThe document you are requesting is forbidden.\r\n</body>\r\n</html>";
	exit;
}



if (isset($_GET['cat'])) {
$linkCategory = $_GET['cat'];
} else {
$linkCategory = 0;
}



// pagination
$limit          = 30;
$sql =  sprintf("SELECT COUNT(id) FROM affiliSt_links WHERE category = %d AND approved = '1'",
					   quote_smart($linkCategory));
$totalrows = mysql_result(mysql_query($sql),0);
 
$lpage = $_GET['lpage'];

if ($navOpt[7] == 1) {
// html perma
$currentLinksPage = $installDir['value'];
} else {
// php link
	if (isset($_GET['cat'])){
	$currentLinksPage = $_SERVER["PHP_SELF"].'?case=links&ld=1&cat='.$_GET['cat'].'&';
	} else {
	$currentLinksPage = $_SERVER["PHP_SELF"].'?case=links&ld=1&';
	}
}

if(empty($lpage)){
$lpage = 1;
}
        
$limitvalue = $lpage * $limit - ($limit);



// get the link listings
$sql = sprintf("SELECT * FROM affiliSt_links WHERE category = %d AND approved = '1' ORDER BY added ASC LIMIT $limitvalue, $limit",
					   quote_smart($linkCategory));
$getLinksDetails = mysql_query($sql, $databaseConnect) or die(mysql_error());
$linksDetails = mysql_fetch_assoc($getLinksDetails);


// page numbers
$numofpages = $totalrows / $limit;

	if ($numofpages > 1) {
		$lholder = '<div id="pagLinks">';
		
		// previous page link
		if($lpage != 1){ 
		$pageprev = $lpage - 1;
		
		if ($navOpt[7] == 1) {
		// html perma
			if (isset($_GET['cat'])){
			$lholder .= '<a href="'.$currentLinksPage.'links/'.$pageprev.'/1/'.strip_tags($_GET['cat']).'.html">&lt Prev</a> '; 
			} else {
			$lholder .= '<a href="'.$currentLinksPage.'linksh/'.$pageprev.'/1.html">&lt Prev</a> '; 
			}
		} else {
		// php link
		$lholder .= '<a href="'.$currentLinksPage.'case=links&lpage='.$pageprev.'">&lt Prev</a> '; 
		}

		}else{
		$lholder .= '&lt Prev ';
		}
		
		
		 
		
		for($i = 1; $i <= $numofpages; $i++){
			if($i == $lpage){
			$lholder .= $i.' ';
			}else{
		
			if ($navOpt[7] == 1) {
			// html perma
				if (isset($_GET['cat'])){
				$lholder .= '<a href="'.$currentLinksPage.'links/'.$i.'/1/'.strip_tags($_GET['cat']).'.html">'.$i.'</a> ';
				} else {
				$lholder .= '<a href="'.$currentLinksPage.'linksh/'.$i.'/1.html">'.$i.'</a> ';
				}
			} else {
			// php link
			$lholder .= '<a href="'.$currentLinksPage.'case=links&lpage='.$i.'">'.$i.'</a> ';
			}
			
			}
		}
		
		// check for remainder results with %
		if(($totalrows % $limit) != 0){
			if($i == $lpage){
			$lholder .= $i.' ';
			}else{
		
			if ($navOpt[7] == 1) {
			// html perma
				if (isset($_GET['cat'])){
				$lholder .= '<a href="'.$currentLinksPage.'links/'.$i.'/1/'.strip_tags($_GET['cat']).'.html">'.$i.'</a> ';
				} else {
				$lholder .= '<a href="'.$currentLinksPage.'linksh/'.$i.'/1.html">'.$i.'</a> ';
				}
			} else {
			// php link
			$lholder .= '<a href="'.$currentLinksPage.'case=links&lpage='.$i.'">'.$i.'</a> ';
			}
		
			}
		}
		
		// next page link
		if(($totalrows - ($limit * $lpage)) > 0){
		$pagenext = $lpage + 1;
		
		if ($navOpt[7] == 1) {
		// html perma
			if (isset($_GET['cat'])){
			$lholder .= '<a href="'.$currentLinksPage.'links/'.$pagenext.'/1/'.strip_tags($_GET['cat']).'.html">Next &gt;</a> ';
			} else {
			$lholder .= '<a href="'.$currentLinksPage.'linksh/'.$pagenext.'/1.html">Next &gt;</a> ';
			}
		} else {
		// php link
		$lholder .= '<a href="'.$currentLinksPage.'case=links&lpage='.$pagenext.'">Next &gt;</a>'; 
		}
		
		}else{
		$lholder .= 'Next &gt;'; 
		}
		
		$lholder .= '</div>';
	}








$box_content = new XTemplate ("skins/".$configSkin['value']."/styleTemplates/links.tpl");

if ($linksDetails) {
	
	do {
		$box_content->assign("WEBSITELINK", $linksDetails['url']);
		$box_content->assign("WEBSITE", $linksDetails['title']);
		$box_content->assign("WEBSITEDESCRIPTION", $linksDetails['description']);
		$box_content->parse("links.li");
	
		} while ($linksDetails = mysql_fetch_assoc($getLinksDetails));
		
		$box_content->assign("PAGELINKS", $lholder);

		$box_content->parse("links");
		$box_content = $box_content->text("links");


} else {

		$box_content->parse("nolinks");
		$box_content = $box_content->text("nolinks");
}
?>